#ifndef _FINEGERPRINT_HPP
#define _FINEGERPRINT_HPP

/* FLAG CODES */
#define CHECK_ID                0x70 // Check if the requested user ID exists.
#define ADD_NEW                 0x71 // Adding more fingerprints to a current existing user ID.
#define CONTINUE                0x74 // There is more data to be sent.
#define AUTO_ID                 0x79 // Automatically assign user ID in enrollment.
#define CHECK_FINGER            0x84 // Check if the finger is already enrolled.
#define CHECK_FINGER_AUTO_ID    0x85 // Check if the finger is already enrolled. If not, assign user ID automatically.
#define ADD_DURESS              0x92 // Add duress fingerprints to an existing user ID.

/* ERROR CODES */
#define SUCCESS                 0x61 // Successfully completed.
#define SCAN_SUCCESS            0x62 // Fingerprint input has succeeded.
#define SCAN_FAIL               0x63 // Sensor or fingerprint input has failed.
#define NOT_FOUND               0x69 // There is no requested data found.
#define NOT_MATCH               0x6A // Fingerprint does not match.
#define TRY_AGAIN               0x6B // Fingerprint image is not good.
#define TIME_OUT                0x6C // Timeout for fingerprint input.
#define MEM_FULL                0x6D // Maximum template capacity exceeded.
#define EXIST_ID                0x6E // The requested user ID exists.
#define FINGER_LIMIT            0x72 // The number of fingerprints enrolled in same ID exceeds its limit (10).
#define UNSUPPORTED             0x75 // The command is not supported.
#define INVALID_ID              0x76 // The requested user ID is invalid or missing.
#define TIMEOUT_MATCH           0x7A // Timeout for matching in identification.
#define BUSY                    0x80 // Module is processing another command.
#define CANCELED                0x81 // The command is canceled.
#define DATA_ERROR              0x82 // The checksum of a data packet is incorrect.
#define DATA_OK                 0x83 // The checksum of a data packet is correct.
#define EXIST_FINGER            0x86 // The finger is already enrolled.
#define DURESS_FINGER           0x91 // A duress finger is detected.
#define LOCKED                  0xA1 // Module is locked.
#define REJECTED_ID             0x90 // Authentication mode of the user is AUTH_REJECT or the ID is in the blacklist.
#define ENTRANCE_LIMIT          0x94 // Authentication fails since the entrance limit is exceeded.

typedef struct fp_packet_s {
    uint8_t start_code;
    uint8_t terminal_id[2];
    uint8_t command;
    uint8_t param[4];
    uint8_t size[4];
    uint8_t flag_error;
    uint8_t csum;
    uint8_t end_code;
} fp_packet_t;

/* convert code to string */
const char* code_to_str(int code);

/* initialize fingerprint module */
int fp_init();

/* enroll new finger and return it's id or -1 in case of failure */
int fp_add_user(std::string name, std::string level);

/* turn identification mode and wait for scan and verification, return id or -1
 * in case of failure*/
int fp_identify_user_by_scan();

/* delete enrolled template with id, return 0 or -1 in case of failure */
int fp_delete_user_by_id(std::string id);

/* delete all, return 0 or -1 in case of failure */
int fp_delete_all_users();

/* change template level, return 0 or -1 in case of failure */
int fp_change_user_level(std::string id, std::string level);

#endif // _FINEGERPRINT_HPP
